package cn.azzhu.day02

import org.apache.flink.api.common.functions.MapFunction
import org.apache.flink.streaming.api.scala._

/**
 * @author azzhu
 * @create 2020-09-20 23:51:48
 */
object MapExample {
  def main(args: Array[String]): Unit = {
    //todo 1.获取执行环境
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    env.setParallelism(1)

    //todo 2.数据源
    val stream = env.addSource(new SensorSource)

   // stream.map(r => r.id).print()
   // stream.map(new MyMapFunction).print()

    //输入泛型：SensorReading，输出泛型：String
    stream.map(new MapFunction[SensorReading,String] {
      override def map(value: SensorReading): String = value.id
    }).print()

    env.execute("MapExample")
  }

  class MyMapFunction extends MapFunction[SensorReading,String] {
    override def map(value: SensorReading): String = value.id
  }
}
